let openfilepath = function(id) {
	// console.log( '---id----', id)
	let that = this;
	let filePath = ''
	let fileList = ''

	// #ifdef APP
	let main = plus.android.runtimeMainActivity();
	let Intent = plus.android.importClass('android.content.Intent');
	let intent = new Intent(Intent.ACTION_GET_CONTENT);
	// pdf文件
	intent.setType("application/pdf");
	intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, false); //关键！多选参数
	intent.addCategory(Intent.CATEGORY_OPENABLE);
	main.startActivityForResult(intent, 200);
	// 获取回调
	main.onActivityResult = function(requestCode, resultCode, data) {
		let Activity = plus.android.importClass('android.app.Activity');
		let ContentUris = plus.android.importClass('android.content.ContentUris');
		let Cursor = plus.android.importClass('android.database.Cursor');
		let Uri = plus.android.importClass('android.net.Uri');
		let Build = plus.android.importClass('android.os.Build');
		let Environment = plus.android.importClass('android.os.Environment');
		let DocumentsContract = plus.android.importClass('android.provider.DocumentsContract');

		// 给系统导入 contentResolver
		let contentResolver = main.getContentResolver();
		plus.android.importClass(contentResolver);
		// 返回路径
		let path = '';
		if (resultCode == Activity.RESULT_OK) {
			if (data.getData() != null) {
				let uri = data.getData()
				//this 当前mainClass实例
				path = getPath(this, uri)
				if (path) {
					console.log("path-->", path)
				} else {
					console.log("上传失败")
				}
			} else {
				try {
					let ClipData = plus.android.importClass('android.content.ClipData');
					let clipData = new ClipData();
					clipData = data.getClipData();
					if (clipData != null) {
						for (let i = 0; i < clipData.getItemCount(); i++) {
							let item = clipData.getItemAt(i);
							let uri = item.getUri();
							let url = getPath(this, uri);
							fileList.push(url);
						}
					}
					console.log("fileList--->", fileList)
				} catch (e) {
					console.log(e);
				}
			}

			// console.log(path);
		} else {
			// console.log(path);
		}

		function getPath(context, uri) {
			try {
				let isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
				if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
					// ExternalStorageProvider
					//一些三方的文件浏览器会进入到这个方法中，例如ES
					//QQ文件管理器不在此列
					if (isExternalStorageDocument(uri)) {
						let docId = DocumentsContract.getDocumentId(uri);
						let split = docId.split(':');
						let type = split[0];
						// 如果是手机内部存储
						if ('primary' == type.toLowerCase()) {
							return Environment.getExternalStorageDirectory() + '/' + split[1];
						} else {
							return '/storage/' + type + '/' + split[1];
						}
					}
					// DownloadsProvider
					else if (isDownloadsDocument(uri)) {
						let id = DocumentsContract.getDocumentId(uri);
						if (id.indexOf('raw:') > -1) {
							id = id.replace('raw:', '');
						}
						// 不同系统获取的id开头可能不一样，在这后面便是真实的地址
						if (id.substring(0, 5) == 'msf:') {
							return id.substring(5, id.length);
						}
						let contentUri = ContentUris.withAppendedId(Uri.parse(
							'content://downloads/public_downloads'), ContentUris.parseId(uri));
						return getDataColumn(context, contentUri, null, null);
					}
					// MediaProvider
					else if (isMediaDocument(uri)) {
						let MediaStore = plus.android.importClass('android.provider.MediaStore');
						let docId = DocumentsContract.getDocumentId(uri);
						let split = docId.split(':');
						let type = split[0];
						let contentUri = null;

						if ('image' == type.toLowerCase()) {
							contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
						} else if ('video' == type.toLowerCase()) {
							contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
						} else if ('audio' == type.toLowerCase()) {
							contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
						}
						let selection = '_id=?';
						let selectionArgs = [split[1]];
						return getDataColumn(context, contentUri, selection, selectionArgs);
					}
				}
				// MediaStore (and general)
				else if ('content' == uri.getScheme().toLowerCase()) {
					if (isGooglePhotosUri(uri)) {
						return uri.getLastPathSegment();
					} else if (isQQMediaDocument(uri)) {
						let paths = uri.getPath();
						let Environment = plus.android.importClass('android.os.Environment');
						let fileDir = Environment.getExternalStorageDirectory();
						let files = plus.android.importClass('java.io.File');
						let file = new files(fileDir, paths.substring('/QQBrowser'.length, paths.length));
						return file.getPath();
					}

					return getDataColumn(context, uri, null, null);
				}
				// File
				else if ('file' == uri.getScheme().toLowerCase()) {
					return uri.getPath();
				}
				return null;
			} catch (e) {
				console.log(e);
				return null;
			}
		}

		// 通过uri 查找出绝对路径
		function getDataColumn(context, uri, selection, selectionArgs) {
			try {
				let MediaStore = plus.android.importClass('android.provider.MediaStore');
				let cursor = null;
				let column = MediaStore.MediaColumns.DATA;
				let projection = [column];
				cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
				if (cursor != null && cursor.moveToFirst()) {
					let column_index = cursor.getColumnIndexOrThrow(column);
					return cursor.getString(column_index);
				}
			} catch (e) {
				console.log(e);
				return null;
			}
		}

		function isExternalStorageDocument(uri) {
			return 'com.android.externalstorage.documents' == uri.getAuthority() ? true : false;
		}

		function isDownloadsDocument(uri) {
			return 'com.android.providers.downloads.documents' == uri.getAuthority() ? true : false;
		}

		function isMediaDocument(uri) {
			return 'com.android.providers.media.documents' == uri.getAuthority() ? true : false;
		}
		/**
		 * 使用第三方qq文件管理器打开
		 *
		 * @param uri
		 * @return
		 */
		function isQQMediaDocument(uri) {
			return 'com.tencent.mtt.fileprovider' == uri.getAuthority() ? true : false;
		}
		/**
		 * @param uri The Uri to check.
		 * @return Whether the Uri authority is Google Photos.
		 */
		function isGooglePhotosUri(uri) {
			return 'com.google.android.apps.photos.content' == uri.getAuthority() ? true : false;
		}
	}
	// #endif
}

export {
	openfilepath
}